/* 
 * RoomMgr.cs
 * Part of Gamadus Engine. Visit www.gamadus.de.vu!
 * 
 * [DONE] Commenting finished.
 */
 
using System;
using System.Collections.Generic;

namespace Gamadus.Engine
{
	/// <summary>
    /// Holds the room list and the current room.
    /// Provides methods to go to a specified room.
    /// </summary>
	public class RoomMgr : SingletonManager<RoomMgr>
	{
		/// <summary>
		/// Gets the room you're currently in
		/// </summary>
		public Room CurrentRoom
		{
			get
			{
				return currentRoom;
			}
		}
		private Room currentRoom;
		
		private List<Room> rooms = new List<Room>();

		/// <summary>
    	/// Goes to another room, leaving the current room
    	/// </summary>
    	/// <param name="lev">The room to go to</param>
		public void GoTo(Room room)
		{
			if(currentRoom != null)
				currentRoom.leaveRoom = true;
			if(currentRoom != null && !currentRoom.persistent)
			{
				currentRoom.Instances.Clear();
			}
			currentRoom = room;
			room.GoTo();
		}
		
		/// <summary>
		/// Goes to the first room of the game and starts the game
		/// </summary>
		public void GoToFirst()
		{
			GoTo(rooms[0]);
		}
		
		/// <summary>
		/// Creates a new room
		/// </summary>
		/// <param name="name">The name of the room</param>
		/// <returns>The created instance of Room</returns>
		public Room CreateRoom(int id)
		{
			Room lev = new Room(id);
			RoomMgr.Instance.rooms.Add(lev);
			return lev;
		}
	}
}
